from kafka.admin import KafkaAdminClient

# 配置Kafka集群的Broker地址列表，直接使用字符串
bootstrap_servers = '47.97.221.154:9092,47.97.221.154:9093,47.97.221.154:9094'

# 创建KafkaAdminClient实例
admin_client = KafkaAdminClient(bootstrap_servers=bootstrap_servers)  # 注意这里需要使用关键字参数

# 获取所有topics的列表
try:
    topics = admin_client.list_topics()
    # 打印所有topics
    print("Available topics:")
    for topic in topics.topics.keys():
        print(topic)
finally:
    # 关闭admin客户端
    admin_client.close()